package com.todo.strategy.online.application.api.controller;

import com.todo.common.common.entity.response.BizResponse;
import com.todo.strategy.online.application.convert.StrategyConvert;
import com.todo.strategy.online.application.entity.bo.PlatformStrategyBO;
import com.todo.strategy.online.application.entity.bo.PlatformStrategyDetailBO;
import com.todo.strategy.online.application.service.PlatformStrategyService;
import com.todo.strategy.online.service.api.PlatformStrategyApi;
import com.todo.strategy.online.service.api.response.PlatformStrategyBaseResponse;
import com.todo.strategy.online.service.api.response.PlatformStrategyDetailResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author azhebuxing
 * @date 2025/2/27 22:34
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/api/platform/strategy")
@Tag(name = "服务端-计划集合接口", description = "服务端-计划集合接口")
public class PlatformStrategyApiController implements PlatformStrategyApi {

    @Resource
    private PlatformStrategyService platformStrategyService;


    @Override
    @Operation(summary = "根据id查询平台策略信息")
    @PostMapping("/queryPlatformStrategyById")
    public BizResponse<PlatformStrategyBaseResponse> queryPlatformStrategyById(@RequestBody Long platformStrategyId) {
        if (platformStrategyId == null || platformStrategyId <= 0){
            return BizResponse.paramError("查询异常，请刷新后重新操作");
        }
        PlatformStrategyBO platformStrategyBO = platformStrategyService.queryPlatformStrategyInfoById(platformStrategyId);
        return BizResponse.success(StrategyConvert.convertToPlatformStrategyBaseResponse(platformStrategyBO));
    }

    @Override
    @Operation(summary = "根据id查询平台策略详情")
    @PostMapping("/queryPlatformStrategyDetailById")
    public BizResponse<PlatformStrategyDetailResponse> queryPlatformStrategyDetailById(@RequestBody Long platformStrategyId) {
        if (platformStrategyId == null || platformStrategyId <= 0){
            return BizResponse.paramError("查询异常，请刷新后重新操作");
        }
        PlatformStrategyDetailBO platformStrategyDetailBO = platformStrategyService.queryPlatformStrategyDetailById(platformStrategyId);
        return BizResponse.success(StrategyConvert.convertToPlatformStrategyDetailResponse(platformStrategyDetailBO));
    }

    @Override
    @Operation(summary = "根据id列表查询平台策略信息")
    @PostMapping("/queryPlatformStrategyList")
    public BizResponse<List<PlatformStrategyBaseResponse>> queryPlatformStrategyList(@RequestBody List<Long> platformStrategyIdList) {
        if (CollectionUtils.isEmpty(platformStrategyIdList)){
            return BizResponse.paramError("查询异常，请刷新后重新操作");
        }
        List<PlatformStrategyBO> platformStrategyBOS = platformStrategyService.queryPlatformStrategyInfoByIdList(platformStrategyIdList);
        return BizResponse.success(StrategyConvert.convertToPlatformStrategyBaseResponseList(platformStrategyBOS));
    }
}
